package com.ymatou.iapi.notify.testcase;

import com.ymatou.iapi.notify.parameter.SendSpeedNotifyBean;
import com.ymatou.iapi.notify.service.SendSpeedNotifyCall;
import com.ymttest.business.service.AssertService;
import com.ymttest.business.service.NotifyCallService;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.YMTDateUtil;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.Date;
import java.util.Map;

/**
*发送批量通知
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SendSpeedNotify{
	private static SendSpeedNotifyBean sendspeednotifyBean;
	private static SendSpeedNotifyCall sendspeednotifyCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("发送批量通知");
	}

	@Before
	public void caseUp() {
		sendspeednotifyBean=new SendSpeedNotifyBean();
		sendspeednotifyCall=new SendSpeedNotifyCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(sendspeednotifyCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSpeedNotify_01() {
		Logger.start(true,"发送批量通知");
		try {
			int notifySenderUserId = 30156393;
			sendspeednotifyBean = NotifyCallService.initSendSpeedNotify(notifySenderUserId);
			String date = YMTDateUtil.getBeforeOrNextDay(1,"MM/dd/yyyy HH:mm:ss");
			sendspeednotifyBean.setEndTime(date);
			sendspeednotifyCall.setData(sendspeednotifyBean);
			sendspeednotifyCall.callService();			
			Logger.verifyEquals("Success",sendspeednotifyCall.getString("Status"),"验证Status");
			int notifyId = sendspeednotifyCall.getJsonObject().get("Result").getAsJsonObject().get("NotifyId").getAsInt();
			Map map = new ImDefaultWapper().selectImNotifyByNotifyId(notifyId).get(0);
			Logger.verifyEquals(sendspeednotifyBean.getNotifySenderUserId(),Integer.parseInt(map.get("MsgFromId").toString()),"验证发送方id");
			Logger.verifyEquals(sendspeednotifyBean.getMessage(),map.get("Message").toString(),"验证通知消息");
			Date date1 = YMTDateUtil.getDate(sendspeednotifyBean.getEndTime(),"MM/dd/yyyy HH:mm:ss");
			Date date2 = YMTDateUtil.getDate(map.get("EndTime").toString(),YMTDateUtil.YMDHMS);
			AssertService.assertTime(date1,date2,"验证endtime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSpeedNotify_03() {
		Logger.start(true,"发送批量通知");
		try {
			int notifySenderUserId = 19000002;
			sendspeednotifyBean = NotifyCallService.initSendSpeedNotify(notifySenderUserId);
			String date = YMTDateUtil.getBeforeOrNextDay(1,"MM/dd/yyyy HH:mm:ss");
			sendspeednotifyBean.setEndTime(date);
			sendspeednotifyCall.setData(sendspeednotifyBean);
			sendspeednotifyCall.callService();
			Logger.verifyEquals("Success",sendspeednotifyCall.getString("Status"),"验证Status");
			int notifyId = sendspeednotifyCall.getJsonObject().get("Result").getAsJsonObject().get("NotifyId").getAsInt();
			Map map = new ImDefaultWapper().selectImNotifyByNotifyId(notifyId).get(0);
			Logger.verifyEquals(sendspeednotifyBean.getNotifySenderUserId(),Integer.parseInt(map.get("MsgFromId").toString()),"验证发送方id");
			Logger.verifyEquals(sendspeednotifyBean.getMessage(),map.get("Message").toString(),"验证通知消息");
			Date date1 = YMTDateUtil.getDate(sendspeednotifyBean.getEndTime(),"MM/dd/yyyy HH:mm:ss");
			Date date2 = YMTDateUtil.getDate(map.get("EndTime").toString(),YMTDateUtil.YMDHMS);
			AssertService.assertTime(date1,date2,"验证endtime");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SendSpeedNotify_02() {
		Logger.start(true,"发送批量通知,通知号不存在");
		try {
			int notifySenderUserId = 123456;
			sendspeednotifyBean = NotifyCallService.initSendSpeedNotify(notifySenderUserId);
			String date = YMTDateUtil.getBeforeOrNextDay(1,"dd/MM/yyyy HH:mm:ss");
			sendspeednotifyBean.setEndTime(date);
			sendspeednotifyCall.setData(sendspeednotifyBean);
			sendspeednotifyCall.callService();
			Logger.verifyEquals("BussinessError",sendspeednotifyCall.getString("Status"),"发送通知异常");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}